package com.geiv.backend.service;

import cn.hutool.core.util.IdUtil;
import com.geiv.backend.mapper.TeacherMapper;
import com.geiv.backend.request.AddRequest;
import com.geiv.backend.request.AddStudent;
import com.geiv.backend.request.LoginMessage;
import com.geiv.backend.result.Teacher_GradeList;
import com.geiv.backend.result.Teacher_NoSelectedStudent;
import com.geiv.backend.result.Teacher_StudentList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * FileName:TeacherService
 * Author:  shadowsouls
 * Date:    2021/6/13 15:52
 * Description:
 */
@Service
public class TeacherService {
    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    TeacherMapper mapper;

    public Teacher_StudentList getTeacher_StudentListByTeacherId(String tid) {

        return mapper.selectTeacher_StudentListByTeacherId(tid);
    }

    public Teacher_GradeList getTeacher_GradeListBySIdAndTId(String sid, String tid) {
        return new Teacher_GradeList(sid, mapper.selectGradeBySidAndTid(sid, tid));
    }

    public String switchSubjectNameToSJId(String name) {
        return mapper.switchSubjectNameToId(name);
    }

    public void addGrade(AddRequest addRequest) {
        mapper.addGrade(addRequest.getStudentId(), addRequest.getGrade(), addRequest.getTime(), switchSubjectNameToSJId(addRequest.getSubject()));
    }
    // 删除成绩
    public void deleteGrade(String gid){
        mapper.deleteGrade(gid);
    }
    //将学生移出管理
    public void deleteStudent(String TWSid){
        mapper.deleteStudent(TWSid);
    }
    //获取未选课的学生
    public List<Teacher_NoSelectedStudent> getNoSelectedStudent(String tid){
        return mapper.getNoSelectedStudent(tid);
    }
    //将学生插入TWS表中
    public void insertStudentToTWS(String tid,List<String> sidList){
        sidList.forEach(sid -> {
            mapper.insertStudentToTWS(sid,tid);
        });
    }
    //在student表和user表中添加学生 单个
    public void addStudent(AddStudent request){
        String uuid= IdUtil.randomUUID();
        String studentId=request.getStudentId();
        String userFlag="student";
        String userName=request.getStudentId();
        String name=request.getName();

        mapper.insertStudentToStudentTable(studentId,name,uuid);
        mapper.insertStudentToUserTable(userName,userFlag,uuid);
    }

    //获得教师的id
    public String teacherLogin(String username,String password){
        return mapper.teacherLogin(username,password);
    }
}
